package com.example.menhoo.toollibrary.common.helper;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.menhoo.toollibrary.R;


/**
 * Created by yanglei on 15/9/15.
 */
public class MessageUtil {
    private static Toast mToast;
    private static AlertDialog.Builder mBuild;
    private static AlertDialog mAlertDialog;

    public static void showSingletonToast(Context context, String text) {
        try {
            if (mToast == null) {
                mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
            }
            mToast.setText(text);
            mToast.show();
        } catch (Exception e) {};
    }

    public static void showLongToast(Context context, int res) {
        try {
            Toast.makeText(context, res, Toast.LENGTH_LONG).show();
        } catch (Exception e) {};
    }

    public static void showShortToast(Context context, int res) {
        try{
            Toast.makeText(context, res, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {};

    }

    public static void showLongToast(Context context, String text) {
        try {
            Toast.makeText(context, text, Toast.LENGTH_LONG).show();
        } catch (Exception e) {};
    }

    public static void showShortToast(Context context, String text) {
        try{
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {};

    }

    public static void ShowAlertSingletonOneDialog(Context context,String title,String text,String btnText,DialogInterface.OnClickListener DialogInterfaceOnClick)
    {
        try {
            if (mBuild == null) {
                mBuild = new AlertDialog.Builder(context);
            }
            if(mAlertDialog!=null){
                mAlertDialog.dismiss();
            }
            mAlertDialog=mBuild.setTitle(title)
                    .setMessage(text)
                    .setPositiveButton(btnText, DialogInterfaceOnClick)
                    .show();
        } catch (Exception e) {};


    }
    public static void ShowAlertOneDialog(Context context,String title,String text,String btnText,DialogInterface.OnClickListener DialogInterfaceOnClick)
    {
        AlertDialog.Builder build=new AlertDialog.Builder(context);
        build.setTitle(title)
                .setCancelable(false)
                .setMessage(text)
                .setPositiveButton(btnText, DialogInterfaceOnClick)
                .show();
    }
    public static void ShowAlertDialog(Context context,String title,String text,String btnText,DialogInterface.OnClickListener DialogInterfaceOnClick)
    {
        ShowAlertDialog(context, title, text, btnText, "取消", DialogInterfaceOnClick, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
    }
    public static void ShowAlertDialog(Context context,String title,String text,String btn1Text,String btn2Text,DialogInterface.OnClickListener btn1onclick,DialogInterface.OnClickListener btn2onclick)
    {
        AlertDialog.Builder build=new AlertDialog.Builder(context);
        build.setTitle(title)
                .setMessage(text)
                .setPositiveButton(btn1Text, btn1onclick)
                .setNegativeButton(btn2Text, btn2onclick)
                .show();
    }


    public static void ShowItemAlertDialog(Context ctext,String title,String[] array,DialogInterface.OnClickListener listener)
    {
        final Context context =ctext;
        new AlertDialog.Builder(context) //

                .setTitle(title) // title

                .setItems(array,listener ).setNegativeButton("取消", new DialogInterface.OnClickListener() {

            @Override

            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss(); //关闭alertDialog

            }

        }).show();
    }
}
